#include "widget.h"
#include "ui_widget.h"

#include <QPainter>
#include <QPushButton>
#include <QCursor>
#include <QPixmap>
#include <QLabel>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QProgressBar>
#include <QTimer>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QDateTimeEdit>
#include <QSlider>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPushButton* button = new QPushButton(this);
    button->setText("cursor");
    QPixmap pixmap(":/image.jpg");
    pixmap.scaled(10, 10);
    QCursor cursor(pixmap, 10, 10);
    button->setCursor(cursor);
    button->setShortcut(QKeySequence("a"));

    QLabel* label = new QLabel(this);
    label->setText("123");
    //label->setMargin（10);
    button->setText("&A");

    QProgressBar* progressbar = new QProgressBar(this);
    progressbar->setValue(0);
    QTimer* timer = new QTimer(this);
    timer->start(100);
    connect(timer, &QTimer::timeout, this, [=](){
        int value = progressbar->value();
        if(value > 100)
            {
            return;
        }
        else {
            progressbar->setValue(value + 1);
        }
    });

    QRegularExpression rexp("^1//10{d}$");
    QLineEdit edit;
    edit.move(600, 100);
    edit.setValidator(new QRegularExpressionValidator(rexp));
    if(edit.validator())
    {
        qDebug() << "Ok";
    }
    else
    {
        qDebug() << "Wrong";
    }

    QDateTimeEdit* edit1 = new QDateTimeEdit(this);
    //edit1->se("请输入起止时间");
    qDebug() << edit1->date();
}

Widget::~Widget()
{
    delete ui;
}

/*
//重写paintEvent事件来处理绘图
void Widget::paintEvent(QPaintEvent* event)
{
    //绘图工作放到这里执行，一般不放在构造函数之中，因为可能会出现因窗口最小化、焦点切换等导致绘制的内容丢失
    //QPainter，提供一系列绘图方法；QPaintDevice，画图板，往什么东西上画，QWidegt就是QPaintDevice的子类
    //QPen，画笔——用于绘制边框；QBrush画刷——用于填充内容
    QPainter painter(this);
    QBrush brush;
    brush.setColor(QColor(255, 0, 0));
    brush.setStyle(Qt::CrossPattern);
    painter.setBrush(brush);

    QPen pen;
    pen.setColor(QColor(255, 0, 0));
    pen.setWidth(5);
    pen.setStyle(Qt::DashLine);

    QFont font("微软雅黑", 24);
    painter.setFont(font);

    painter.drawLine(20, 20, 20, 200);
    painter.drawLine(QPoint(20, 20), QPoint(30, 200));
    painter.drawRect(300, 300, 100, 200);
    painter.drawEllipse(400, 400, 50, 50);
    painter.drawText(0, 100, "hello"); //0横坐标，100纵坐标，表示基线位置，四线三格的第三根线

    QPixmap pixmap(":/cat.svg");
    painter.drawPixmap(100, 100, pixmap);

    painter.rotate(180); //绕着0，0进行的旋转
    painter.translate(-800, -600); //重新设置原点
    painter.drawText(0, 400, "reversed text");

}
*/
